package com.wing.device.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wing.common.utils.PageResult;
import com.wing.device.model.response.DeviceInspectExecuteVO;
import com.wing.device.service.DeviceInspectExecuteService;
import com.wing.device.service.DeviceInspectService;
import com.wing.web.db.config.util.DynamicDataSource;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.1.0
 * @Author hz
 * @Date 2024-08-19 15:13
 **/
@Validated
@Api(value = "Admin-设备维修任务管理", tags = "#/device/inspectExecute")
@RestController("inspectExecuteController")
@RequestMapping("device/admin/inspectExecute")
@Slf4j
public class DeviceInspectExecuteController {


    @Resource
    private DeviceInspectExecuteService deviceInspectExecuteService;

    @Resource
    private DeviceInspectService deviceInspectService;



    @ApiOperation(value = "查询设备年检任务列表", notes = "搜索")
    @GetMapping("/list")
    public PageResult<DeviceInspectExecuteVO> list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer limit,
            @RequestParam(defaultValue = "create_time") String sort,
            @RequestParam(defaultValue = "asc") String order,
            String deviceType,
            String inspectExecuteStatus,
            String id,
            String deviceId,
            String taskNo
            ){
        Page<DeviceInspectExecuteVO> pg = new Page<>(page, limit);
        Map map = new HashMap();
        map.put("deviceType", deviceType);
        map.put("inspectExecuteStatus", inspectExecuteStatus);
        map.put("id", id);
        map.put("taskNo", taskNo);
        map.put("deviceId", deviceId);
        String databaseUser = DynamicDataSource.USER_PREFIX;
        if (StringUtils.isNotBlank(DynamicDataSource.name.get())) {
            databaseUser = databaseUser + "-" + DynamicDataSource.name.get();
        }
        map.put("databaseUser", databaseUser);
        IPage<DeviceInspectExecuteVO> list = deviceInspectExecuteService.pageList4app(pg, map);
        //关联相关业务属性
        return new PageResult<>(list.getRecords(), list.getTotal());
    }

}
